<template>
  <div>
    <Myheader title="购物车 - Happy" bg="red" color="#fff"></Myheader>
    <div class="main">
      <MyGoods v-for="val in goodlist" :key="val.id" :obj="val"></MyGoods>
      <Myfooter @change="status" :arr="goodlist"></Myfooter>
    </div>
  </div>
</template>

<script>
import Myheader from "./components/MyHeader";
import Myfooter from "./components/MyFooter";
import MyGoods from "./components/MyGoods";
import { mapState } from "vuex";
import { mapActions } from "vuex";

export default {
  components: {
    Myheader,
    Myfooter,
    MyGoods,
  },
  data() {
    return {
      list: [],
    };
  },
  created() {
    this.asyncGetList();
    // this.$axios({
    //   url: "https://www.escook.cn/api/cart",
    // }).then((res) => {
    //   this.list = res.data.list;
    //   console.log(res);
    // });
  },
  methods: {
    ...mapActions("shop", ["asyncGetList"]),
    status(val) {
      this.list.forEach((obj) => {
        obj.goods_state = val;
      });
    },
  },
  computed: {
    ...mapState({
      goodlist: (state) => state.shop.goodlist,
    }),
  },
};
</script>

<style scoped>
.main {
  padding: 45px 0 50px 0;
}
</style>